/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hoja4;

/**
 *
 * @author luisorozco
 */

// Clase obtenida del libro JavaStructure

public class SinglyLinkedList<T> {
    
    protected int count; // list size
    protected Node<T> head; // ref. to first element
    
    public SinglyLinkedList() 
    // post: generates an empty list
    {
        head = null;
        count = 0;
    }   
    
    public void add(T value)
    // post: value is added to beginning of list
    {
    // note order that things happen:
    // head is parameter, then assigned
        head = new Node<T>(value, head);
        count++;
    }
    
    public T remove()
    // pre: list is not empty
    // post: removes and returns value from beginning of list
    {
        Node<T> temp = head;
        head = head.next(); // move head down list
        count--;
        return temp.getValue();
    }

    public int size()
    // post: returns number of elements in list
    {
        return count;
    }

    public boolean isEmpty() 
    // post: returns true if the list is empty
    {
        return 0 == count;   
    }
}
